package com.yaorange.module.security.controller;

import com.yaorange.module.security.entity.dto.LoginDTO;
import com.yaorange.module.security.entity.vo.ResourcesVO;
import com.yaorange.module.security.service.AuthService;
import com.yaorange.response.Result;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 *  认证/授权控制器
 */
@RestController
public class AuthController {
    @Autowired
    private AuthService authService;

    /**
     *  认证
     * @param loginDTO
     * @return
     */
    @PostMapping("/user/login")
    public Result<String> login(@Valid @RequestBody LoginDTO loginDTO){
        return Result.success(authService.login(loginDTO));
    }


    /**
     *  获取用户信息
     */
    @GetMapping("/user/info")
    public Result<ResourcesVO> getUserInfo(){
        return Result.success(authService.getResources());
    }
}
